MySQL INSERT INTO SELECT Statement
The INSERT INTO SELECT
statement is used to copy the data from one table and insert into another table.
In order to use the INSERT INTO SELECT
statement both the source and destination table column and datatype matches.
Syntax for INSERT INTO SELECT Statement
INSERT INTO table_2
SELECT * FROM table_1
WHERE condition;
Example for INSERT INTO SELECT Statement
INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
This will copy the records from the Suppliers
table to the Customers
table.
Here the SupplierName will be mapped to CustomerName, City to City and Country to Country column of Suppliers
table to Customers
table.